#ifndef  MATERIAL_H
#define  MATERIAL_H
#include "../DXUT/Core/DXUT.h"
// Used for a hashtable vertex cache when creating the mesh from a .obj file
struct CacheEntry
{
	UINT index;
	CacheEntry* pNext;
};


// Material properties per mesh subset
struct Material
{
	WCHAR   strName[MAX_PATH];

	D3DXVECTOR3 vAmbient;
	D3DXVECTOR3 vDiffuse;
	D3DXVECTOR3 vSpecular;

	float fShininess;
	float fAlpha;

	bool bSpecular;

	WCHAR   strTexture[MAX_PATH];
	ID3D11ShaderResourceView* pTexture;
	//ID3DX11EffectTechnique* hTechnique;
	Material()
	{
		memset(strName,0,sizeof(WCHAR)*MAX_PATH);
		vAmbient = D3DXVECTOR3(0,0,0);
		vDiffuse = D3DXVECTOR3(0,0,0);
		vSpecular = D3DXVECTOR3(0,0,0);
		fShininess = 0;
		fAlpha = 0;
		bSpecular = false;
		memset(strTexture,0,sizeof(WCHAR)*MAX_PATH);
		pTexture = NULL;
	}

	Material(Material& mat)
	{
		wcscpy_s(strName,mat.strName);
		vAmbient = mat.vAmbient;
		vDiffuse = mat.vDiffuse;
		vSpecular = mat.vSpecular;
		fShininess = mat.fShininess;
		fAlpha = mat.fAlpha;
		bSpecular = mat.bSpecular;
		wcscpy_s(strTexture,mat.strTexture);
		pTexture = mat.pTexture;	
	}
};

struct MESH_ATTRIBUTE_RANGE {
	UINT AttribId;
	UINT FaceStart;
	UINT FaceCount;
	UINT VertexStart;//not ready yet!
	UINT VertexCount;
	UINT MatIndex; //material index number
	MESH_ATTRIBUTE_RANGE()
	{
		AttribId = 0;
		FaceStart = 0;
		FaceCount = 0;
		VertexStart = 0;
		VertexCount = 0;
		MatIndex = 0;
	}
	MESH_ATTRIBUTE_RANGE(const MESH_ATTRIBUTE_RANGE& range)
	{
		AttribId = range.AttribId;
		FaceStart = range.FaceStart;
		FaceCount = range.FaceCount;
		VertexStart = range.VertexStart;
		VertexCount = range.VertexCount;
		MatIndex = range.MatIndex;
	}

	MESH_ATTRIBUTE_RANGE(UINT iAttribId, UINT iFaceStart, UINT iFaceCount, UINT iVertexStart = 0, UINT iVertexCount = 0, UINT iMatIndex = 0)
	{
		AttribId = iAttribId;
		FaceStart = iFaceStart;
		FaceCount = iFaceCount;
		VertexStart = iVertexStart;
		VertexCount = iVertexCount;
		MatIndex = iMatIndex;
	}
};

struct MAT_FACE_ID {
	UINT MatID;
	UINT VertID0;
	UINT VertID1;
	UINT VertID2;
	
	static bool compare(MAT_FACE_ID id1, MAT_FACE_ID id2)
	{
		return (id1.MatID < id2.MatID);
	}
};
#endif